package com.qiqidream.admin.monitor.service.impl;

import com.qiqidream.admin.common.entity.PageEntity;
import com.qiqidream.admin.monitor.model.entity.LogInfo;
import com.qiqidream.admin.monitor.service.LogService;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author QiQiDream
 * @since 2019/12/21 9:30
 */
@Service
public class LogServiceImpl implements LogService {

    @Resource
    private MongoTemplate mongoTemplate;

    @Override
    public void saveLog(LogInfo logInfo) {
        mongoTemplate.save(logInfo);
    }

    @Override
    public PageEntity<LogInfo> page(Integer page, Integer size) {
        long total = mongoTemplate.count(new Query(),LogInfo.class);

        List<LogInfo> logInfos = mongoTemplate.find(new Query().skip((page - 1) * size).limit(size), LogInfo.class);

        System.out.println(total);
        return new PageEntity<>(total, logInfos);
    }
}
